package admin_sales;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class Orders_search extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

    @Test
  public void testUntitled() throws Exception {
	Actions actions = new Actions(driver);
    driver.manage().window().maximize();
    driver.get(baseUrl + "admin");
    driver.findElement(By.id("username")).clear();
    driver.findElement(By.id("username")).sendKeys("admin");
    driver.findElement(By.id("login")).clear();
    driver.findElement(By.id("login")).sendKeys("admin123");
    driver.findElement(By.cssSelector("input.form-button")).click();
    driver.findElement(By.cssSelector("a[title=\"close\"] > span")).click();
    TimeUnit.SECONDS.sleep(3);
    actions.moveToElement(driver.findElement(By.xpath("//ul[@id='nav']/li[2]/a/span"))).build().perform();
    assertEquals("Orders", driver.findElement(By.xpath("//ul[@id='nav']/li[2]/ul/li/a/span")).getText());
    driver.findElement(By.xpath("//ul[@id='nav']/li[2]/ul/li/a/span")).click();    
    driver.findElement(By.id("sales_order_grid_filter_real_order_id")).clear();
    driver.findElement(By.id("sales_order_grid_filter_real_order_id")).sendKeys("100000034");
    driver.findElement(By.cssSelector("button[title=\"Search\"]")).click();
    TimeUnit.SECONDS.sleep(3);
    assertEquals("100000034", driver.findElement(By.xpath("//table[@id='sales_order_grid_table']/tbody/tr/td[2]")).getText());
    TimeUnit.SECONDS.sleep(3);
    driver.findElement(By.cssSelector("button[title=\"Reset Filter\"]")).click();
    TimeUnit.SECONDS.sleep(3);
    assertEquals("", driver.findElement(By.id("sales_order_grid_filter_real_order_id")).getText());
    
  }

   private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  
  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}
